﻿using System;
using System.Data.OleDb;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using System.Windows.Forms;

namespace TotalCrytography.Data
{

    public class DataProvider
    {
        public static string m_ConnectionString;
        public static OleDbConnection m_Connection;
        public static OleDbDataAdapter m_Adapter;
        public static OleDbCommand m_Command;


        public static string ConnectionString
        {
            get
            {
                return m_ConnectionString;
            }
            set
            {
                m_ConnectionString = value;
            }
        }

        public static void Connect()
        {
            LoadConnectionString();
            m_Connection = new OleDbConnection(ConnectionString);
            m_Connection.Open();
        }

        public static void Disconnect()
        {
            m_Connection.Close();
        }


        static bool LoadConnectionString()
        {
            //string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"|DataDirectory|\\Data\\Data.accdb\"";
            //conn = conn.Replace("|DataDirectory|", );
            //XmlDocument doc = new XmlDocument();
            //doc.Load("ConnectionString.xml");
            //XmlElement root = doc.DocumentElement;
            string path = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" + Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\") + 1);
            path += "Data\\Data.accdb\"";
            //ConnectionString = root.InnerText;
            if (path.IndexOf("Microsoft Office") == -1)
                ConnectionString = path;
            return true;
        }



    }

}